package com.book.manage.config.result;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ControllerAdvice
// @ExceptionHandler(Exception.class)
public class Result<T> {
    //    返回code
    private Integer code;
    //    返回msg
    private String msg;
    //    返回date
    private T date;

    //  成功不返回信息
    public static <T> Result<T> success() {
        return new Result<>(1, "成功", null);
    }

    //    成功返回信息
    public static <T> Result<T> success(T date) {
        return new Result<>(1, "成功", date);
    }

    //    失败返回信息
    @ExceptionHandler(Exception.class)
    public static <T> Result<T> error(T date) {
        return new Result<>(0, "失败", date);
    }

}
